<script>

import TitleLevelCard from "/src/views/manage/talent/titleLevel/components/title-level-card.vue";
import SaveDialog from "/src/views/manage/talent/titleLevel/components/save-dialog.vue";

export default {
  components: {TitleLevelCard, SaveDialog},
  data() {
    return {
      // 获取所有工作系列
      series: [],
    }
  },
  mounted() {
    this.getSeries();
  },
  methods: {
    getSeries() {
      let loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });

      this.$kt.requestSecurity.send({
        uri: "/business-talent-web/series/getAllHasTitleLevel",
        stateSuccess: (res) => {
          this.series = res.data;
          // 根据series.titleLevels的number排序，从大到小
          this.series.forEach(item => {
            item.titleLevels.sort((a, b) => {
              return b.number - a.number;
            });
          });
          setTimeout(() => {
            loading.close();
          }, 500);
        },
        stateFail: (res) => {
          this.$message.error(res.errMsg);
          setTimeout(() => {
            loading.close();
          }, 500);
        }
      })
    }
  }
}
</script>

<template>
  <div class="box">
    <div class="card-box">
      <title-level-card
          v-for="item in series"
          :item="item"
          @toSave="(e)=>$refs.saveDialog.open(e)"
      ></title-level-card>

      <save-dialog
          ref="saveDialog"
          @saveSuccess="getSeries"
      ></save-dialog>
    </div>
  </div>
</template>

<style lang="scss" scoped>

.card-box {
  text-align: center;
}

</style>